package cn.yeziji.forum.dto.pay.path;

import cn.yeziji.forum.basic.pay.PayPathInfo;
import cn.yeziji.forum.common.enums.status.FileStatus;
import cn.yeziji.forum.exception.FileException;
import cn.yeziji.forum.exception.PayException;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;

import java.io.Serializable;

/**
 * 获取指定的微信路径地址
 *
 * @author hwy
 * @since 2023/07/29 12:25
 **/
@Data
@Builder
@NoArgsConstructor
@AllArgsConstructor
public class WechatPathDTO extends PayPathInfo implements Serializable {
  /**
   * apiclient_key.pem
   */
  private String keyPath;

  /**
   * apiclient_cert.pem
   */
  private String certPath;

  /**
   * apiclient_cert.p12
   */
  private String certP12Path;

  /**
   * platform_cert.pem
   */
  private String platformCertPath;

  /**
   * 映射路径地址
   *
   * @param filename 文件名
   * @param filePath 文件路径
   * @return {@link WechatPathDTO} 微信支付文件路径
   */
  public WechatPathDTO mappingPath(final String filename, final String filePath) {
    switch (filename) {
      case "apiclient_key.pem":
        this.keyPath = filePath;
        break;
      case "apiclient_cert.pem":
        this.certPath = filePath;
        break;
      case "apiclient_cert.p12":
        this.certP12Path = filePath;
        break;
      case "platform_cert.pem":
        this.platformCertPath = filePath;
        break;
      default:
        throw new FileException(FileStatus.FILE_NAME_IS_NULL);
    }
    return this;
  }
}
